package com.example.express.controller;

import com.example.express.model.TransPackage;
import com.example.express.service.DomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TPController {
    private final DomainService service;

    @Autowired
    public TPController(DomainService service) {
        this.service = service;
    }

//    @GetMapping("/esInPkg/{pkgId}")
//    public List<ExpressSheet> getEsInPkg(@PathVariable String pkgId) {
//        return service.getListInPackage(pkgId);
//    }

    /**
     * 按照节点名称和包裹状态获取包裹
     * @param node
     * @param status
     * @return
     */
    @GetMapping("/pkgs")
    public List<TransPackage> getByNodeAndStatus(@RequestParam("nodeName") String node, @RequestParam("status") int status) {
        return service.getPkgsByNodeAndStatus(node, status);
    }

    /**
     * 揽收某个节点的包裹
     * @param node
     */
    @PutMapping("/pkgCollect")
    public void pkgCollect(@RequestParam("nodeName") String node) {
        service.receiveEs(node);
        service.dispatchEs(node);
    }

    /**
     * 运输某个节点的某个包裹
     * @param pkgId
     * @param node
     * @param transPackage
     */
    @PutMapping("pkgTrans/{pkgId}")
    public void pkgTrans(@PathVariable String pkgId, @RequestParam("nodeName") String node, @RequestBody TransPackage transPackage) {
        service.setOffPkg(pkgId, node, transPackage);
    }

    /**
     * 包裹到站
     * @param pkgId
     */
    @PutMapping("pkgArrive/{pkgId}")
    public void arrivePkg(@PathVariable String pkgId) {
        service.arrivePkg(pkgId);
    }
}
